<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>获取指定位置字符</title>
</head>

<body>
  <label for="inputChar">请输入字符串：</label>
  <input type="text" id="inputChar">
  <label for="inputIndex">请输入数字：</label>
  <input type="number" id="inputIndex">
  <button onclick="getChar()">获取指定位置字符</button>
  <p id="showChar"></p >
  <script>
    function getChar() {
      var charStr = document.getElementById('inputChar').value;
      var index = document.getElementById('inputIndex').value;
      if (index >= 0 && index < charStr.length) {
        var char = charStr.charAt(index);
        document.getElementById('showChar').innerHTML = `字符串中第 ${index} 个字符是: ${char}`;
      } else {
        document.getElementById('showChar').innerHTML = '输入的数字超出字符串范围或无效';
      }
    }
  </script>
</body>

</html>